The present invention relates to a document image skew detection method for detecting a skew of an image (particularly, a document image) input from an image input device such as an image scanner.
Image scanners have been used for many years as devices for inputting document images. Conventionally, desktop scanners, generally known as flatbed scanners, have been used, but in recent years, the development and commercialization of manually operated hand-held scanners compact in size and convenient to carry around have been proceeding.
With such hand-held scanners, the probability of scanning a document image askew is very high, depending especially on the way that the user operates the scanner. Ideally, the scanner should be moved over the document in a direction parallel or perpendicular to the direction of text orientation. This should prevent the input document image from being scanned askew.
In reality, however, since the hand-held scanner allows great freedom in user operation, the probability that the user will scan the document by holding the scanner askew to the orientation of the text is very high. This could happen regardless of whether the user is aware of it or not. When the scanner is moved askew to the document, the document image is also scanned askew.
To solve this problem, the following techniques have been proposed in the prior art.
Japanese Unexamined Patent Publication No. 63-180180 discloses a technique whereby each side of a rectangle bounding the text area of a document image is obtained by a straight-line approximation based on the scanned document image. Then, the angle between the thus obtained straight line (side) and the outer periphery of the image is computed, and this angle is taken to represent the skew of the document image.
Japanese Unexamined Patent Publication No. 7-192086 discloses a technique whereby, from a plurality of scanned document images, points defining a boundary between black and white pixels on the image are extracted and a straight regression line representing these extracted points is computed. The skew angle of the document image can be found from the values of the regression coefficients of the thus computed straight regression line.
Japanese Unexamined Patent Publication No. 7-282195 discloses a technique which creates a projection profile by accumulating the number of black pixels for each line of the input document image. The skew angle can be found from the variance in the thus created projection profile.
The above techniques then correct the skew of the document by rotating the input document image in a direction that offsets the skew in accordance with the calculated skew angle of the document.
These techniques, however, involve the following problems.
For example, when a portion of a document is scanned by a scanner, characters will be present over the entire image area scanned. Especially, in the case of hand-held scanners which are made compact in size, the width that they can scan at a time is small, which quite often leads to a situation where only a portion of a document can be scanned. In such cases, the rectangular area bounding the text area of the image coincides with the outer periphery of the scanned image. With the technique disclosed in Japanese Unexamined Patent Publication No. 63-180180, therefore, if the document is scanned as described above, the skew image of the document image cannot be obtained based on the angle that each side of the rectangle bounding the text area makes with the outer periphery of the image.
On the other hand, when the document image contains not only characters but also graphics such as line drawings or photos, the boundary between the black and white pixels in the graphic image portion is not a straight line. As a result, the slope angle of the straight regression line of the boundary does not represent the skew angle of the document image. Accordingly, with the technique disclosed in Japanese Unexamined Patent Publication No. 7-192086, which calculates the skew of the document image based on the slope of the straight-regression line taken along the boundary points between the black and white pixels in an image area, the probability of erroneously calculating the skew angle increases greatly if the document image also contains graphics.
Further, in the case of a document image containing graphics, when calculating the skew angle of the document by creating a projection profile of the document image, if there is a graphic that differs in density from the document image (text area), it is likely that the distribution of the entire projection profile containing such graphics will differ from the projection profile of the document image. Accordingly, the technique disclosed in Japanese Unexamined Patent Publication No. 7-282195 cannot address such a problem.
In view of the above-outlined problems, it is an object of the present invention to provide a document image skew detection method capable of detecting the skew angle of a document with high accuracy even when only a portion of the document image is scanned or when the document image contains graphics.
To achieve the above object, according to the present invention, there is provided a method for detecting a skew of a document image, comprising the steps of: segmenting an input document image into segmentation regions each having a predetermined width; detecting a region formed from consecutive lines containing black pixels as a consecutive-line region from within each of the segmentation regions; extracting the detected consecutive-line region as a partial image based on a predetermined condition; calculating the skew angle of the partial image; and determining the skew angle of the document image based on the calculated skew angle of the partial image.
According to the present invention, preferably, the step of calculating the skew angle of the partial image includes: setting coordinate axes for the partial image; approximating the coordinates of the black pixels present in the sub-region by a straight line; and taking the slope of the approximated straight line to represent the skew angle of the partial image.
According to the present invention, preferably, the step of extracting the partial image includes: calculating the ratio of the number of black pixels to the number of pixels within the consecutive-line region; and extracting the consecutive-line region as the partial image if the number of black pixels lies within a preset range.
According to the present invention, preferably, the step of extracting the partial image includes: determining whether the height of the consecutive-line region lies within a preset height range; and extracting the consecutive-line region as the partial image if it is determined that the height of the consecutive-line region lies within the preset range.
According to the present invention, preferably, the step of extracting the partial image includes; finding the width of an area, within the consecutive-line region, where there are no contiguous black pixels along the direction of the lines; comparing the width of the no-black-pixel area with a preset width; and extracting the consecutive-line region as the partial image if the result of the comparison shows that the width of the area is smaller than the preset width.
According to the present invention, preferably, the step of detecting the consecutive-line region includes detecting a plurality of consecutive-line regions, the step of extracting the partial image includes extracting a plurality of partial images, the step of calculating the skew angle of the partial image includes calculating the skew angle for each of the plurality of partial images, and the step of determining the skew angle of the document image includes determining the skew angle of the document image based on the calculated skew angles of the plurality of partial images.
According to the present invention, preferably, the step of determining the skew angle of the document image includes: counting skew angle information classified according to the sign of the skew angle calculated for each of the plurality of partial images; and determining the skew angle of the document image based on the skew angle information of whichever sign resulted in a greater count.
According to the present invention, preferably, the step of determining the skew angle of the document image includes: obtaining an average value of the skew angles of the plurality of partial images; and determining the average value as the skew angle of the document image.
According to the present invention, preferably, the step of determining the skew angle of the document image includes: calculating the angle of a diagonal of the extracted partial image; comparing the angle of the diagonal with the skew angle of the partial image; and determining the skew angle of the document image based on the skew angle of the partial image if the skew angle of the partial image is smaller than the angle of the diagonal.